<template>
  <div class="app-container">
    <div v-if="processInfo">
      <el-row :gutter="20">

        <el-col :span="6" :xs="24">
          <user-card :process-info="processInfo" />
        </el-col>

        <el-col :span="18" :xs="24">
          <el-card>
            <el-tabs v-model="activeTab">
              <el-tab-pane label="Activity" name="activity">
                <activity />
              </el-tab-pane>
              <el-tab-pane label="Timeline" name="timeline">
                <timeline />
              </el-tab-pane>
              <el-tab-pane label="Account" name="account">
                <account :process-info="processInfo" />
              </el-tab-pane>
            </el-tabs>
          </el-card>
        </el-col>

      </el-row>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import UserCard from './components/UserCard'
import Activity from './components/Activity'
import Timeline from './components/Timeline'
import Account from './components/Account'

import { fetchArticle, removeProcessById } from '@/api/workflow/process'

export default {
  name: 'Profile',
  components: { UserCard, Activity, Timeline, Account },
  data() {
    return {
      processId: 4,
      processInfo: null,
      listLoading: true,
      activeTab: 'activity'
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'avatar',
      'roles'
    ])
  },
  created() {
    this.getInfo()
  },
  methods: {
    getInfo() {
      this.listLoading = true
      fetchArticle(this.processId).then(response => {
        if (response.status === 200) {
          this.processInfo = response.data
        }

        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      })
    },
    handleJumpProcess(row) {
      this.$router.push({ path: '/workflow/process' })
    },
    handleDelete(row, index) {
      removeProcessById(row.identity).then(() => {
        this.$notify({
          title: 'Success',
          message: 'Update Successfully',
          type: 'success',
          duration: 2000
        })
        this.getList()
      })
    }
  }
}
</script>
